package com.itheima.d2_Stream;
/**
 * Stream学习
 */

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
public class demo1 {
    public static void main(String[] args) {
        List<String> list = new ArrayList<>();
        list.add("张三丰");
        list.add("张无忌");
        list.add("周芷若");
        list.add("赵敏");
        list.add("张天宝");

        //1.从集合找出姓张的放到新集合---->startWith
        List<String> zhanglist = new ArrayList<>();
        for (String s : list) {
            if(s.startsWith("张")){
                zhanglist.add(s);
            }
        }
        System.out.println(zhanglist);

        //找长度为3的姓名
        List<String> sizeof3list = new ArrayList<>();
        for (String s : list) {
            if(s.length() == 3){
                sizeof3list.add(s);
            }
        }
        System.out.println(sizeof3list);


        /**
         * 使用Stream流实现
         *                  1.filter过滤器
         *                  2.链式编程
         */
        list.stream().filter(s -> s.startsWith("张")).filter(s -> s.length()==3).forEach(s -> System.out.println(s));
    }
}
